<template lang="html">
  <div class="">
    <div class="t_header">
      <el-form :inline="true" :model="formInline" label-width="180px" class="demo-form-inline">
        <el-form-item>
          <el-input style="width:240px" v-model="formInline.name" placeholder="供应商/维修厂/运营商名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="formInline.select" placeholder="全部">
            <el-option label="全部" value=""></el-option>
            <el-option label="未发货" value="'0'"></el-option>
            <el-option label="已发货" value="1"></el-option>
            <el-option label="已完成" value="2"></el-option>
            <el-option label="已关闭" value="3"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" class="el_button" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="body">
      <el-table :data="tableData.list" style="width: 100%">
        <el-table-column prop="sm_name" label="供应商名称" align="center" width="">
            <template slot-scope="scope">
                <el-popover placement="right" trigger="click" @show="getUserInfo(scope.row)">
                  <div style="line-height:25px">
                    <p><img class="user_avatar" :src="userInfo.head_pic" alt=""></p>
                    <p>姓名：{{userInfo.name}}</p>
                    <p>手机号：{{userInfo.phone}}</p>
                  </div>
                  <el-button slot="reference" style="cursor:pointer" size="mini" type="primary" plain>{{scope.row.sm_name}}</el-button>
                </el-popover>
            </template>
        </el-table-column>
        <el-table-column label="申请方" align="center" width="">
          <template slot-scope="scope">
            <p v-if="scope.row.type == 1">维修厂</p>
            <p v-if="scope.row.type == 2">运营商</p>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" align="center" label="申请时间" width=""></el-table-column>
        <el-table-column prop="" label="状态" align="center" width="">
          <template slot-scope="scope">
            <p v-if="scope.row.audit_status == 0">未发货</p>
            <p v-if="scope.row.audit_status == 1">已发货</p>
            <p v-if="scope.row.audit_status == 2">已完成</p>
            <p v-if="scope.row.audit_status == 3">已关闭</p>
          </template>
        </el-table-column>
        <el-table-column prop="settlement_price" align="center" label="订单总金额" width=""></el-table-column>
        <el-table-column prop="company" align="center" label="公司名称" width=""></el-table-column>
        <el-table-column  label="订单详情" align="center">
          <template slot-scope="scope">
              <el-button @click="onShow(scope.row)" size="mini" type="primary" plain>查看详情</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="" label="操作" align="center" width="">
            <template slot-scope="scope">
  <el-button @click="handleClick(scope.row)"
             type="text"
             size="small">提醒发货</el-button>
</template>
        </el-table-column>
      </el-table>
      <el-pagination layout="prev, pager, next":page-count="tableData.rows" :current-page="currentPage" @current-change="changePage" align="center"></el-pagination>
    </div>

    <el-dialog title="订单详情" width="40%" :visible.sync="dialogTableVisible">
        <el-table :data="orderData">
            <el-table-column align="center" property="materiel" label="油品名称"></el-table-column>
            <el-table-column align="center" property="num" label="申请数量"></el-table-column>
            <el-table-column align="center" property="settlement_price" label="结算价"></el-table-column>
            <!-- <el-table-column align="center" property="" label="合计">
              <template slot-scope="scope">
                <p>{{scope.row.num * scope.row.settlement_price}}</p>
              </template>
            </el-table-column> -->
        </el-table>
    </el-dialog>


  </div>
</template>

<script>
export default {
  data () {
    return {
      formInline: {},
      tableData: {},
      userInfo: [],
      dialogTableVisible:false,
      orderData: [],
      currentPage:1
    }
  },
  created () {
    this.getOilDeliverList();
  },
  methods: {
    getOilDeliverList (page = 1) {
      this.currentPage = page;
      this.$http2.getOilDeliverList({
        page: page,
        name: this.formInline.name,
        status: this.formInline.select
      }).then(res => {
        this.tableData = res.data.code == 1 ?
        res.data.data : []
      })
    },
    changePage (e) {
      this.getOilDeliverList(e);
    },
    onShow (e) {
      this.dialogTableVisible = true;
      this.$http2.getOilDetail({
        type: e.type,
        sm_id: e.sm_id,
        id: e.id
      }).then(res => {
        res.data.code == 1 ?
          this.orderData = res.data.data : []
      })
    },
    getUserInfo (e) {
      this.$http2.getSmUserInfo({
        sm_id: e.sm_id
      }).then(res => {
        this.userInfo = res.data.data
      })
    },
    handleClick (e) {
      this.$confirm("提醒发货").then( () => {
        this.$http2.remindDeliver({
          sm_id: e.sm_id
        }).then(res => {
          if (res.data.code == 1) {
            this.$message.success(res.data.msg)
          } else {
            this.$message.error(res.data.msg)
          }
        })
      }).catch( () =>{});
    },
    onSubmit () {
      this.getOilDeliverList();
    },
  }
}
</script>

<style lang="css" scoped>
@import "../../my-style/app.css";
.user_avatar {
  width: 50px;
  height: 50px;
  border-radius: 100%;
  display: block;
}
</style>
